//
//  ADJgCustomAdapterTestUnifiedNativeAdView.m
//  ADJgCustomPlatform
//
//  Created by Suancai on 2021/9/7.
//

#import "ADJgCustomAdapterGDTUnifiedNativeAdView.h"

@interface ADJgAdapterNativeAdData()

- (instancetype)initWithTitle:(NSString *)title
                      content:(NSString *)content
          imageUrlStringArray:(NSArray<NSString *> *)imageUrlStringArray
                    iconImage:(nullable UIImage *)iconImage
                 iconImageUrl:(nullable NSString *)iconImageUrl
          shouldShowMediaView:(BOOL)shouldShowMediaView;

@end


@interface ADJgCustomAdapterGDTUnifiedNativeAdView ()
{
    ADJgAdapterNativeAdData *_data;
    CGFloat _width;
}
@end

@implementation ADJgCustomAdapterGDTUnifiedNativeAdView

#pragma mark - ADJgAdapterNativeAdViewDelegate

- (void)adjg_registViews:(NSArray<UIView *> *)clickViews {
    [self registerDataObject:_adData clickableViews:clickViews];
    if([self.unifiedNativeAdDelegate respondsToSelector:@selector(adjgCustomUnifiedNativeAdViewRender:)]) {
        [self.unifiedNativeAdDelegate adjgCustomUnifiedNativeAdViewRender:self];
    }
}

- (ADJgAdapterNativeAdData *)data {
    return _data;
}

- (nullable UIView *)adjg_mediaViewForWidth:(CGFloat)width {
    [self.mediaView muteEnable:YES];
    return self.mediaView;
}

- (void)adjg_platformLogoImageDarkMode:(BOOL)darkMode loadImageBlock:(void (^)(UIImage * _Nullable))block {
    if (!block) {
        return;
    }
    block(nil);
}

- (ADJgAdapterRenderType)renderType {
    return ADJgAdapterRenderTypeNative;
}

- (void)adjg_unRegistView {
    [self unregisterDataObject];
}

- (void)adjg_close {
    [self.unifiedNativeAdDelegate adjgCustomUnifiedNativeAdViewClose:self];
}

- (BOOL)adjg_closeButtonExist {
    return NO;
}

#pragma mark - Set

- (void)setAdData:(GDTUnifiedNativeAdDataObject *)adData {
    _adData = adData;
    NSArray *imageUrlStringArray = @[];
    if(_adData.imageUrl) {
        imageUrlStringArray = @[_adData.imageUrl];
    }
    _data = [[ADJgAdapterNativeAdData alloc] initWithTitle:_adData.title
                                                     content:_adData.desc
                                         imageUrlStringArray:imageUrlStringArray
                                                   iconImage:nil
                                                iconImageUrl:_adData.iconUrl
                                         shouldShowMediaView:_adData.isVideoAd];
}


#pragma mark - ADJgAdViewInfoProtocol

- (ADJgAdapterPlatform)adjg_platform {
    return @"gdt";
}

@end
